import 'dart:convert';

import 'package:acgn_pioneer/pages/reader/reader_page_main.dart';
import 'package:acgn_pioneer/pages/sort/sort_main_page.dart';
import 'package:acgn_pioneer/pages/test_life.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import '../public.dart';

/// 路由handler定义
var notFoundHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return new Scaffold(
      body: Center(
          child: Text(
    "route not found!",
    style: TextStyle(color: Colors.red, fontSize: Rem(30)),
  )));
});

var homePageHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return WidgetProvider.getInstance().getHomePage(new HomePage());
});

var splashPageHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return SplashPage();
});

var readPageHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  var comicId = params['comicId'];
  var chapterId = params['chapterId'];
  var comicIds = params['comicIds'];
  return ReaderPageMain(
      comicIds: comicIds == null ? [] : jsonDecode(comicIds[0]),
      // comicIds: [7119],
      // comicId: 7119,
      comicId: comicId == null ? null : int.parse(comicId[0]),
      chapterId: chapterId == null ? null : int.parse(chapterId[0]));
});

var myIndexHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return MyIndexPage();
});

var myAccountHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return MyAccount();
});

var myCreditHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return MyCreditPage();
});
var myEditHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return MyEditPage();
});

var pursuePageHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return PursuePage();
});
var historyPageHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return HistoryPage();
});
var registerPageHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return RegisterPage();
});
var verificationCodePageHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return VerificationCodePage(params);
});
var inviteCodePageHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return InviteCodePage();
});

var sortMainPage = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return SortMainPage();
});

var webViewHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return WebViewPage(url: params['url'][0]);
});
var settingHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return SettingPage();
});

var testHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return TestPage();
});

var testLifeHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return TestLife();
});
